class Solution {
public:
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        int cnt=0;
        queue<int> q;
        stack<int> st;
        for(int i=0;i<students.size();i++)
        {
            q.push(students[i]);
        }
        for(int i=sandwiches.size()-1;i>=0;i--)
        {
            st.push(sandwiches[i]);
        }
        while(q.size() && st.size())
        {
            while(cnt<=q.size() && st.top()!=q.front())
            {
                q.push(q.front());
                q.pop();
                cnt++;
            }
            if(cnt>q.size())
                break;
            cnt=0;
            if(st.top()==q.front())
            {
                st.pop();
                q.pop();
            }
           
        }
        return q.size();
    }
};
